<?php

namespace App\Models;

class UserInfos extends Base
{
    protected $table = 'user_infos';

    protected $fillable = [
        'id','user_id','company_name','company_email','company_phone','company_type','company_industry','company_size','master_name',
        'master_phone','master_position','certification','hr_size','hr_department','hr_position','created_at','updated_at'
    ];

    protected $casts = ['certification' => 'array'];

    /**
     * 获取列表
     * @param array $params 条件参数
     * @param array $fields 查询的字段
     * @param int $limit 分页数量
     * @return mixed
     */
    protected function getOneList($params = []){
        $lists = $this->where(function ($query) use ($params) {
                if(isset($params['user_id']) && $params['user_id']) {
                    $query ->where('user_id',$params['user_id']);
                }
                if(isset($params['status']) && $params['status']) {
                    $query ->where('status',$params['status']);
                }
                if(isset($params['type']) && $params['type']) {
                    $query ->where('type',$params['type']);
                }
            })
            ->leftJoin('company_infos as type',function($join){ $join->on('type.id','=','company_type'); })
            ->leftJoin('company_infos as industry',function($join){ $join->on('industry.id','=','company_industry'); })
            ->leftJoin('company_infos as size',function($join){ $join->on('size.id','=','company_size'); })
            ->leftJoin('company_infos as hr',function($join){ $join->on('hr.id','=','hr_size'); })
            ->first(['user_infos.*','type.name as type','industry.name as industry','size.name as size','hr.name as hr']);
        return $lists;
    }

}
